<template>
	<view class="parse-container">
		<u-navbar :title="navtitle"> </u-navbar>
		<view class="title" v-if="query.type != 'YSXY'&&query.type != 'SIGN_IN_RULES'">
			{{ title }}
		</view>
		<view class="zxitem-title-info u-flex-y-center"
			v-if="query.type != 'YSXY' && query.type != 'JBCNYKJGS'&&query.type != 'SIGN_IN_RULES'">
			<view class="u-flex-y-center">
				{{ $u.timeFormat(createTime, "yyyy年mm月dd日 hh:MM:ss") }}
				<view class="u-flex-xy-center" style="padding-left: 10rpx"><u-icon name="eye" color="#999"
						size="12"></u-icon>浏览量:
					{{ item.pv || 0 }}
				</view>
				<view style="width: 10rpx"></view>
			</view>
			<u-tag v-if="tag" :text="tag" size="mini" type="success"></u-tag>
			<!-- tag -->
		</view>
		<view class="content">
			<u-parse :content="content" :tagStyle="style"></u-parse>
		</view>
		<view style="height: 10rpx"></view>
	</view>
</template>

<script>
	import {
		getHomeInfo,
		getCompanyNewsInfo
	} from "@/api/index.js";
	import {
		getMarket
	} from "@/api/market.js";
	import {
		getDicts
	} from "@/api/dictdata";
	import qs from "qs"
	export default {
		data() {
			return {
				navtitle: "",
				title: "",
				query: {},
				content: "",
				createTime: "",
				item: {},
				tag: "",
				style: {
					// 字符串的形式
					table: "border-collapse: collapse;text-align: center;",
					td: "border: 1px solid #333;",
					th: "border: 1px solid #333;",
				},
			};
		},
		onLoad(query) {
			this.query = query;
			console.log(query);
			this.init();
		},
		onShareAppMessage: function() {
			let data = {
				url: "/pages/parse/parse",
				query: this.query,
				type: "share",
			}
			return {
				title: this.navtitle, // 动态标题
				path: "/pages/index/index?type=share&data=" + JSON.stringify(data), // 动态路径
				// imageUrl: this.swiperlist.length == 0 ? '' : this.swiperlist[0],
			};
		},
		// 右上角转发到朋友圈
		onShareTimeline() {
			console.log(qs.stringify(this.query));
			return {
				title: this.navtitle, // 动态标题
				query: qs.stringify(this.query),
				// imageUrl: this.swiperlist.length == 0 ? '' : this.swiperlist[0],
			};
		},
		methods: {
			async init() {

				if (this.query.type == "JBCNYKJGS" || this.query.type == "YSXY" || this.query.type ==
					'SIGN_IN_RULES') {
					let {
						data
					} = await getHomeInfo({
						code: this.query.type,
					});
					let title = {
						JBCNYKJGS: '公司简介',
						YSXY: '用户协议及隐私条款',
						SIGN_IN_RULES: "签到规则"
					}
					this.navtitle = title[this.query.type];
					this.title = data.titleName;
					this.content = data.content;
					this.createTime = data.createTime;
					this.item = data;
				} else if (this.query.type == "news") {
					let {
						data
					} = await getCompanyNewsInfo({
						id: this.query.id,
					});
					this.navtitle = "企业资讯";
					this.title = data.title;
					this.content = data.content;
					this.createTime = data.createTime;
					this.item = data;
				} else if (this.query.type == "market") {
					let {
						data
					} = await getMarket({
						id: this.query.id,
					});
					this.navtitle = "热门资讯";
					this.title = data.title;
					this.content = data.content;
					this.createTime = data.createTime;
					this.item = data;
					let dictsdata = await getDicts("hay_market_type");
					let dicts = dictsdata.data.find(item => {
						return item.value == data.marketType;
					});
					this.tag = dicts?.label;
					console.log(dicts, "dictsdata");
					// hay_market_type
				}
			},
		},
	};
</script>

<style>
	page {
		background: #fff;
	}
</style>
<style lang="scss" scoped>
	.parse-container {

		.title {
			font-weight: bold;
			font-size: 32rpx;
			text-align: center;
			padding: 20rpx;
		}

		.content {
			margin: 20rpx;
			background: rgba(169, 224, 143, 0.1);
			box-shadow: 0rpx 0rpx 12rpx rgba(126, 126, 126, 0.5);
			padding: 20rpx;
			border-radius: 12rpx;
		}

		.zxitem-title-info {
			font-size: 12px;
			color: #999;
			padding: 0 20rpx;
			justify-content: space-between;
		}
	}

	// $u-success: #5ac725;
	// $u-success-dark: #53c21d;
	// $u-success-disabled: #a9e08f;
	// $u-success-light: #f5fff0;
</style>